﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChinapnrAPI;
using Uranus.Service.UserService;

namespace Uranus.ChinaService.Receives
{
    public class UserManagerReceive : BaseReceive
    {
        public UserManagerReceive(HttpContext httpContext)
            : base(httpContext)
        {

        }

        #region 用户注册

        /// <summary>
        /// 个人用户开户锁
        /// </summary>
        private static object LockUserRegister = new object();

        /// <summary>
        /// 用户开户回调
        /// </summary>
        public void UserRegister()
        {
            try
            {
                ChinapnrUserManagement chinapnrUserManagement = new ChinapnrUserManagement();
                if (chinapnrUserManagement.VerUserRegister(Request))
                {
                    int userid = int.Parse(this.UsrId.Substring(7, chinapnrUserManagement.UsrId.Length - 7));
                    string content = string.Format("用户{0}成功注册汇付天下  汇付天下ID：{1}", userid, this.UsrCustId);
                    WriteInfoLog("用户开通汇付天下成功", content);
                    if (Service.User.GetUser().AuthUserInfo(new AuthUserRequest()
                    {
                        IDCard = this.IdNo,
                        FullName = this.UsrName,
                        HuiFuCode = this.UsrCustId,
                        UserID = userid,
                        HuiFuName = this.UsrId
                    }).Code == 1)
                    {
                        WriteInfoLog("用户开通汇付天下处理成功", content);
                    }
                    else
                    {
                        WriteInfoLog("用户开通汇付天下处理失败", content);
                    }
                }
                else
                {
                    string content = string.Format("用户:{0},RespCode:{1},RespDesc:{2}", this.MerPriv.Split('|')[0], this.RespCode, this.RespDesc);
                    WriteInfoLog("用户开通汇付天下验证失败", content);
                }
            }
            catch (Exception ex)
            {
                WriteErrorLog("个人用户开户回调出现异常", ex.ToString());
            }
        }

        #endregion
    }
}